<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet/less" href="./less/reset.less">
    <link rel="stylesheet/less" href="./less/mine.less">
    <script src="https://cdn.bootcdn.net/ajax/libs/less.js/4.1.1/less.min.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="https://cdn.bootcdn.net/ajax/libs/qs/6.9.6/qs.js"></script>
    <script src="http://res2.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
    <title></title>
</head>
<body>
    <div id="app">
        <div class="main">
            <div class="login-top">
                <header class="title">
                    <ul>
                        <li @click="goRegister">
                            <ul>
                                <li>
                                    <img :src="userIcon">
                                </li>
                                <li>{{userName}}</li>
                            </ul>
                        </li>
                        <li @click="businessCard">
                            <img src="./img/code.png">
                        </li>
                    </ul>
                    <ul v-show="messageStatus">
                        <li v-for="(item,index) in identity">
                            <ul>
                                <li>{{item.name}}</li>  
                                <li>{{index==1?inviteCode:marketpName+'/'+levelName}}</li>
                            </ul>
                        </li>
                    </ul>
                </header>
            </div>    
            <div class="bulk">
                <div>我的团购</div>
                <ul>
                    <li v-for="(item,index) in bulk" @click=" bulkGoods(index,item.name,item.type)">
                        <img :src="item.img">
                        <div>{{item.name}}</div>
                    </li>
                </ul>
            </div>
            <div class="wallet">
                <ul>
                    <li v-for="(item,index) in wallet" @click="groupJump(index)" v-if="item.status">
                        <img :src="item.img">
                        <div>{{item.name}}</div>
                    </li>
                </ul>
            </div>
            <a href="./index.html">返回首页</a>
        </div>
    </div>
</body>
</html>
<script type="module">
    import { myLevel } from './js/request/api.js';
    import { shareLink } from './js/public.js';
    Vue.prototype.public = {shareLink};
    let app = new Vue({
        el: '#app',
        data: {
            userIcon: '',
            userName: '',
            messageStatus: false,
            inviteCode: '',
            userId: '',
            levelName: '',
            marketpName: '',
            identity:[
                {
                    name: '身份级别',
                    rank: '团长/粉丝'
                },
                {
                    name: '邀请码',
                    rank: 'SJSHRN'
                }
            ],
            bulk:[
                {
                    img: './img/team.png',
                    name: '我的团'
                },
                {
                    img: './img/spelling.png',
                    name: '拼购中',
                    type: 1
                },
                {
                    img: './img/notSpell.png',
                    name: '拼成功',
                    type: 2
                },
                {
                    img: './img/auditFailure.png',
                    name: '拼失败',
                    type: 3
                }
            ],
            wallet:[
                {
                    img: './img/wallet.png',
                    name: '我的钱包',
                    status: true
                },
                {
                    img: './img/earnings.png',
                    name: '我的收益',
                    status: true
                },
                {
                    img: './img/address.png',
                    name: '收货地址',
                    status: true
                },
                {
                    img: './img/payment.png',
                    name: '设置密码',
                    status: true
                },
                {
                    img: './img/loginOut.png',
                    name: '退出登录',
                    status: true
                },
            ]
        },
        mounted(){
            let that = this;
                that.userMessage();
                that.public.shareLink();
        },
        methods:{
            
            bulkGoods(index,name,type){
                let userData = JSON.parse(localStorage.getItem("userData"));
                if(userData == null){
                    let url = './login.html';
                        window.location.href = url;
                    return false;    
                }
                if(index == 0){
                    let url = "./team.html";
                    window.location.href = url;
                }else{
                    let url = "./orderDetails.html?name="+name+"&type="+type;
                    window.location.href = url;
                }
            },

            userMessage(){
                let that = this;
                let userData = JSON.parse(localStorage.getItem("userData"));
                    if(userData == null){
                        that.userIcon = './img/photo.png';
                        that.userName = '登录/注册';
                        that.wallet[3].status = false;
                        that.wallet[4].status = false;
                        return false;    
                    }
                    that.messageStatus = true;
                    that.userIcon = userData.userIcon;
                    that.userName = userData.userName;
                    that.inviteCode = userData.inviteCode;
                    that.userId = userData.userId;
                    myLevel({
                        userId: that.userId
                    }).then((res)=>{
                        that.levelName = res.data.levelName;
                        that.marketpName = res.data.marketpName;
                    }).catch((error)=>{
                        console.log(error);
                    })
            },
            groupJump(index){
                let userData = JSON.parse(localStorage.getItem("userData"));
                
                if(userData == null){
                    let url = './login.html';
                        window.location.href = url;
                    return false;    
                }

                if(index==0){
                    let url = './myWallet.html';
                    window.location.href = url;
                }else if(index == 1){
                    let url = './earnings.html';
                    window.location.href = url;
                }else if(index == 2){
                    let url = './addressManagement.html?type='+1;
                    window.location.href = url;
                }else if(index == 3){
                    let url = './setPassword.html';
                    window.location.href = url;
                }else if(index == 4){
                    let url = './login.html';
                    window.location.href = url;
                    localStorage.clear();
                }
            },
            businessCard(){
                let userData = JSON.parse(localStorage.getItem("userData"));
                let url;
                if(userData == null){
                    url = './login.html';
                    window.location.href = url;
                    return false;    
                }
                url = './businessCard.html';
                window.location.href = url;
            },
            goRegister(){
                let that = this;
                let userData = JSON.parse(localStorage.getItem("userData"));
                let url;
                if(userData == null){
                    url = './login.html';
                    window.location.href = url;
                    return false;    
                }
            },
        },
    })
</script>